﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;

namespace LogicUniversity.Manager
{
    public partial class ApproveAdjustment : System.Web.UI.Page
    {
        IssueAdjustmentVoucher voucher = new IssueAdjustmentVoucher();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<Discrepancy> adjustments = voucher.getAdjustmentIssueAbove();

                if (adjustments == null || adjustments.Count<=0)
                {
                    lblMsg.Text = "Currently No Adjustments Items.";
                    btnApprove.Visible = false;
                }
                AdjustmentItemsView.DataSource = adjustments;
                AdjustmentItemsView.DataBind();
            }
        }

        protected void btnApprove_Click(object sender, EventArgs e)
        {
            HashSet<int> voucherIDs = new HashSet<int>();
            foreach (GridViewRow row in AdjustmentItemsView.Rows)
            {
                voucherIDs.Add(Convert.ToInt32(((HiddenField)row.FindControl("voucherID")).Value));
            }

            string supID = Session["UserID"] as string;
            voucher.approveAdjustments(voucherIDs,supID);
        }

        
    }
}